﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using CrystalDecisions.Windows;


namespace QLThuoc_report
{
    public partial class LoaiThuoc : Form
    {
        public LoaiThuoc()
        {
            InitializeComponent();
        }
        private int _MaLoaiThuoc;

        public int MaLoaiThuoc
        {
            get { return _MaLoaiThuoc; }
            set { _MaLoaiThuoc = value; }
        }
        private void LoaiThuoc_Load(object sender, EventArgs e)
        {
            txtMa.Hide();
            txtMa.Text = MaLoaiThuoc.ToString();
            SqlConnection  conn = new SqlConnection("Data Source =(local);Initial Catalog=QLThuoc;Integrated Security=true");
            SqlDataAdapter da = new SqlDataAdapter("SELECT     dbo.tbl_LoaiThuoc.TenLoaiThuoc AS 'Tên Loại Thuốc', SUM(dbo.tbl_Thuoc.SoLuongTon) AS 'Số Lượng' FROM         dbo.tbl_Thuoc INNER JOIN     dbo.tbl_LoaiThuoc ON dbo.tbl_Thuoc.MaLoaiThuoc = dbo.tbl_LoaiThuoc.MaLoaiThuoc GROUP BY dbo.tbl_LoaiThuoc.TenLoaiThuoc", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            //lay duong dan du chuy?n sang máy tính nào c?ng ko b? l?i, ko có c?ng ðc nhýng sang máy tính khác s? ko ch?y ðc
            string path = Application.StartupPath;
            path = path.Substring(0, path.LastIndexOf("bin")) + "TKeLoaiThuoc.rpt";
            TKeLoaiThuoc report = new TKeLoaiThuoc();
            report.SetDataSource(dt);
            crystalReportViewer1.ReportSource = report;
        }
    }
}
